# 云胡的编程周报第 006 期
时间:2023/9/18 - 2023/9/24
# 一、点滴记录
# 1
给「云胡图书馆」添加用户可以选择的高亮颜色,没什么技术难度,就是把高亮的颜色变为一个响应式变量即可。
# 2
更改器方法与访问器方法的区别
# 2.1 访问器方法
只访问对象而不更改对象的方法称为访问器方法。
# 2.2 更新器方法
访问对象并且更改对象的方法称为更新器方法。
# 3
Node.js ``18
的版本在运行 vuepress
的时候会报错:
i 「wds」: Project is running at http://0.0.0.0:8080/
i 「wds」: webpack output is served from /yunhu-library-doc/
at F:\CodeProject\ProjectDocs\yunhu-library-docs\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at F:\CodeProject\ProjectDocs\yunhu-library-docs\node_modules\graceful-fs\graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
2
3
4
5
6
7
8
9
10
解决方法:在原来的 package.json
文件的 scripts
的vuepress
命令前加上 set NODE_OPTIONS=--openssl-legacy-provider &
原来的:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
}
2
3
4
5
改为:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docs:dev": "set NODE_OPTIONS=--openssl-legacy-provider & vuepress dev docs",
"docs:build": "set NODE_OPTIONS=--openssl-legacy-provider & vuepress build docs"
}
2
3
4
5
# 4
MyBatis Plus
批量插入数据的三种方式
# 4.1 for 循环中 insert 或者 save
在 for
循环中一条一条插入数据到数据库中。
void testInsert() {
Date sdate = new Date();
for (int i = 0;i < 10; i++) {
ProjectRemarkTableEntity projectRemarkTableEntity = new ProjectRemarkTableEntity();
projectRemarkTableEntity.setUserName("yunhu");
projectRemarkTableEntity.setEssayTitle("优化一下阅读体验");
projectRemarkTableEntity.setEssayContent("比如切换主题");
projectRemarkTableEntity.setSubmitDate(LocalDateTime.now());
projectRemarkMapper.insert(projectRemarkTableEntity);
}
Date edate = new Date();
System.out.printf("执行时长:%d 毫秒." , (edate.getTime() - sdate.getTime()));
}
2
3
4
5
6
7
8
9
10
11
12
13
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1253b822] was not registered for synchronization because synchronization is not active
2023-09-25 13:58:40.026 WARN 62628 --- [ main] com.zaxxer.hikari.HikariConfig : HikariPool-1 - idleTimeout is close to or more than maxLifetime, disabling it.
2023-09-25 13:58:40.026 INFO 62628 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-09-25 13:58:40.592 INFO 62628 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@1244869566 wrapping com.mysql.cj.jdbc.ConnectionImpl@13b4ee4e] will not be managed by Spring
==> Preparing: INSERT INTO t_project_remark ( user_name, essay_title, essay_content, submit_date ) VALUES ( ?, ?, ?, ? )
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T13:58:40.004879(LocalDateTime)
<== Updates: 1
Committing JDBC Connection [HikariProxyConnection@1244869566 wrapping com.mysql.cj.jdbc.ConnectionImpl@13b4ee4e]
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1253b822]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@619854a3] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1191123629 wrapping com.mysql.cj.jdbc.ConnectionImpl@13b4ee4e] will not be managed by Spring
==> Preparing: INSERT INTO t_project_remark ( user_name, essay_title, essay_content, submit_date ) VALUES ( ?, ?, ?, ? )
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T13:58:40.717177100(LocalDateTime)
<== Updates: 1
Committing JDBC Connection [HikariProxyConnection@1191123629 wrapping com.mysql.cj.jdbc.ConnectionImpl@13b4ee4e]
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@619854a3]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4d4600fb] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1934770572 wrapping com.mysql.cj.jdbc.ConnectionImpl@13b4ee4e] will not be managed by Spring
==> Preparing: INSERT INTO t_project_remark ( user_name, essay_title, essay_content, submit_date ) VALUES ( ?, ?, ?, ? )
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T13:58:40.796141300(LocalDateTime)
<== Updates: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
可以看到每次插入一条数据都要创建一个 SqlSession
,效率很低。
执行时长:1430
毫秒.
# 4.2 saveBatch() 批量插入
@Test
void testSaveBatch() {
Date sdate = new Date();
List<ProjectRemarkTableEntity> insertList = new ArrayList<>();
for (int i = 0;i < 10; i++) {
ProjectRemarkTableEntity projectRemarkTableEntity = new ProjectRemarkTableEntity();
projectRemarkTableEntity.setUserName("yunhu");
projectRemarkTableEntity.setEssayTitle("优化一下阅读体验");
projectRemarkTableEntity.setEssayContent("比如切换主题");
projectRemarkTableEntity.setSubmitDate(LocalDateTime.now());
insertList.add(projectRemarkTableEntity);
}
appProjectRemarkService.saveBatch(insertList);
Date edate = new Date();
System.out.printf("执行时长:%d 毫秒." , (edate.getTime() - sdate.getTime()));
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2023-09-25 14:09:20.900 WARN 51348 --- [ main] com.zaxxer.hikari.HikariConfig : HikariPool-1 - idleTimeout is close to or more than maxLifetime, disabling it.
2023-09-25 14:09:20.900 INFO 51348 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-09-25 14:09:21.480 INFO 51348 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@405881980 wrapping com.mysql.cj.jdbc.ConnectionImpl@7741507c] will be managed by Spring
==> Preparing: INSERT INTO t_project_remark ( user_name, essay_title, essay_content, submit_date ) VALUES ( ?, ?, ?, ? )
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
==> Parameters: yunhu(String), 优化一下阅读体验(String), 比如切换主题(String), 2023-09-25T14:09:20.897110700(LocalDateTime)
执行时长:962 毫秒.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
执行时长:962
毫秒。
实际上也是一条一条 insert
,但是减少了很多创建SqlSession
的消耗,提高了效率。
# 4.3 手动拼接 SQL
手动拼接,可以达到真正的批量插入,效率最高。
# 5
在两张表或者多张表插入或者更新数据的时候,我们希望保持数据的一致性,因此我们需要用到数据库的事务。 现在重新复习一下事务的四个特性:
原子性(Atomicity):事务作为一个整体被执行,包含在其中的对数据库的操作要么全部被执行,要么都不执行。
比如一个事务中插入了五条数据,这五条数据要么全部全部插入成功,要么全部插入失败,没有其他情况。
一致性(Consistency):事务应确保数据库的状态从一个一致状态转变为另一个一致状态。
比如小云向小胡转账
100
块钱,那么小云的账户余额-100
,小胡的账户余额+100
,这就保持了一致性,如果小云的账户-100
,而小胡的账户没有+100
,这就不符合一致性。隔离性(Isolation):多个事务并发执行时,一个事务的执行不应影响其他事务的执行。
持久性(Durability):已被提交的事务对数据库的修改应该永久保存在数据库中
Spring Boot
事务的使用很简单,直接在 Service
层的方法上加入 @Transactional
即可。
# 二、新发现
# 1
Linux
命令大全(手册)
https://www.linuxcool.com/ (opens new window)
# 2
Linux
命令搜索
https://wangchujiang.com/linux-command/ (opens new window)
# 3
Flow
https://github.com/pacexy/flow (opens new window)
epub
阅读器的 github
库。
# 4
JSDoc 3
https://www.jsdoc.com.cn/ (opens new window)
JSDoc 3 是一个用于 JavaScript 的API文档生成器,类似于 Javadoc 或 phpDocumentor。可以将文档注释直接添加到源代码中。JSDoc 工具将扫描您的源代码并为您生成一个 HTML 文档网站。
# 5
小林 x 图解计算机基础
https://www.xiaolincoding.com/ (opens new window)
图解计算机网络、操作系统、计算机组成、数据库,让天下没有难懂的八股文!